package org.Demo;


/*
* 某系统的数字密码是一个四位数，如1983，为了安全，需要加密后再传输，加密规则是：对密码中的每位数，都加5，再对
* 10求余，最后将所有数字顺序反转，得到一串加密后的新数，请设计出满足本需求的加密程序！
* */
public class Demo2 {
    public static void main(String[] args) {
        String code = Code(1983);
        System.out.println(code);
    }
    public static String Code(int number){
        int[] numbers = split(number);
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = (numbers[i] + 5)%10;
        }
        reverse(numbers);
        String data = "";
        for (int i = 0; i < numbers.length; i++) {
            data += numbers[i];
        }
        return data;
    }
    public static int[] split(int number){
        int[] numbers = new int[4];
        numbers[0] = number/1000;
        numbers[1] = (number/100)%10;
        numbers[2] = (number/10)%10;
        numbers[3] = number%10;
        return numbers;
    }
    public static void reverse(int[] numbers){
        int temp = numbers[0];
        for (int i = 0,j = numbers.length-1; i < j ; i++,j--) {
            temp = numbers[i];
            numbers[i] = numbers[j];
            numbers[j] = temp;
        }
    }
}
